package com.kasax.android.arch.base.app;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.kasax.android.arch.BasicConstants;
import com.kasax.android.arch.handler.CommonCrashHandler;


public abstract class BaseApp extends Application {
    private static AppInitBradge appInitBradge;

    @Override
    public void onCreate() {
        super.onCreate();

        appInitBradge = AppInitBradge.getInstance();
        appInitBradge.doInit(this, getLogTag(), isDebugModel());
    }


    /**
     * 获取当前正在显示的activity 仅仅是获取不从任务栈中移除
     */
    public static Activity getCurrentAct() {
        return appInitBradge.getCurrentAct();
    }

    public static String getMainThreadName() {
        return appInitBradge.getMainThreadName();
    }

    public static int getAppProcessId() {
        return appInitBradge.getAppProcessId();
    }

    public static int getMainThreadId() {
        return appInitBradge.getAppProcessId();
    }

    public static Looper getAppLooper() {
        return appInitBradge.getAppLooper();
    }

    public static Handler getAppHandler() {
        return appInitBradge.getAppHandler();
    }

    public static Context getContext() {
        return appInitBradge.getContext();
    }

    protected String getLogTag() {
        return BasicConstants.LOG_TAG;
    }

    protected boolean isDebugModel() {
        return true;
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        CommonCrashHandler.getInstance().init(this, (thread, throwable) -> handleUncaughtException(thread, throwable));
    }

    protected void handleUncaughtException(Thread thread, Throwable throwable) {

    }
}
